package org.agent.systeminit;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

import org.agent.common.Constants;
import org.agent.pojo.SystemConfig;
import org.agent.service.systemConfig.SystemConfigService;
import org.apache.log4j.Logger;
import org.springframework.web.context.support.WebApplicationContextUtils;

/**
 * 监听器
 * @author Administrator
 *
 */
public class SystemInit implements ServletContextListener {
	
	private Logger logger = Logger.getLogger(SystemInit.class);

	@Override
	public void contextDestroyed(ServletContextEvent servletContextEvent) {
		// TODO Auto-generated method stub

	}

	@Override
	public void contextInitialized(ServletContextEvent servletContextEvent) {
		// TODO Auto-generated method stub
		
//		-------------------------系统配置项-------------------------------
//		1.拿到IOC容器WebApplicationContext
//		初始化WebApplicationContext
		Constants.webApplicationContext=WebApplicationContextUtils.getWebApplicationContext(servletContextEvent.getServletContext());
		
		if(Constants.webApplicationContext != null){
//			2.拿到systemConfigService	
			SystemConfigService systemConfigService = (SystemConfigService)Constants.webApplicationContext.getBean("systemConfigService");
//			3.调用service方法  初始化已启用的配置项
			SystemConfig systemConfig = new SystemConfig();
			systemConfig.setIsStart(1);
			Constants.systemConfigList=systemConfigService.getSystemConfigListIsStart(systemConfig);
			
			if(Constants.systemConfigList != null){
				Constants.configSystemData();
			}
			
		}
		

		
		

		

	}

}
